<template>
  <el-tree-select ref="baseRef" value-key="id" :props="{ children: 'children', label: 'name' }" v-bind="$attrs">
    <template v-for="(key, name) in $slots" #[name]="slotData">
      <slot :name="name" v-bind="slotData"></slot>
    </template>
  </el-tree-select>
</template>
<script setup lang="ts">
  defineOptions({
    inheritAttrs: false,
  });

  const baseRef = ref();

  const inputMethods: any = {};
  // ElTree方法的再次暴露时再mounted后，在某些时候（比如组件初始化的时候）可能不存在，可以使用 ref.value.getTree().value的方式调用
  const getTree = function () {
    return baseRef;
  };

  inputMethods.getTree = getTree;

  defineExpose(inputMethods);

  onMounted(() => {
    Object.assign(inputMethods, baseRef.value);
  });
</script>
